import os 

def list_files_in_directory(directory):
    try:
        # List all files in the specified directory
        files = [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]
        return files
    except FileNotFoundError:
        print(f"Error: The directory '{directory}' does not exist.")
        return []

def are_files_identical(file1, file2):
    flag = True
    try:
        with open(file1, 'r') as f1, open(file2, 'r') as f2:
            # Read and compare line by line
            for line1, line2 in zip(f1, f2):
                line1 = line1.replace(' ', '').replace('\n', '')
                line2 = line2.replace(' ', '').replace('\n', '')
                if line1 != line2:
                   
                    print(f"  line1 = {line1}, line2 = {line2}")
                    return False
            # Check if one file has extra lines
            return f1.read() == f2.read()
    except FileNotFoundError as e:
        print(f"Error: {e}")
        return False

# Example usage
#file1List = ['001.result.txt', '002.result.txt', '003.result.txt']
file2List = list_files_in_directory("./answer")
file2List.sort()
print(file2List)

for file2 in file2List:
    file1 = file2[:3] + ".result.txt"
    file2 = "./answer/" + file2
    print(f"Comparing {file1} and {file2}")

    if are_files_identical(file1, file2):
        print("The files are identical.")
    else:
        print("The files are not identical.")
